import {getList,getBd} from '../api/search'
const search = {
    namespaced: true,
    state: {
        typelist:[],
        bdlist:[],
        obj:{
            pages:0
        },
        total:0
    },
    mutations: {
        setType(state,res){
            state.typelist=res.data
        },
        setbd(state,res){
            state.bdlist=res.data
            state.total=res.total
        },
        setObj(state){
            state.obj.pages++
        },
        clearbd(state){
            state.bdlist=[];
            state.obj.pages=0
        }
    },
    actions: {
        //清空列表
        clearFn({commit}){
            commit('clearbd')
        },
        //获取列表
        async getbdFn({commit,state},val){
            let {data}=await getBd({pages:state.pages,keyword:val})
            commit('setbd',data)
            commit('setObj')
        },
        //获取类别
        async getType({commit}){
            let {data}=await getList()
            commit('setType',data)
        }
    }
}
export default search